package com.xj.api.bussiness.deviceJpg.service.impl;

import com.xj.api.bussiness.deviceJpg.service.ITbDeviceJpgService;
import com.xj.common.bussiness.deviceJpg.entity.TbDeviceJpg;
import com.xj.common.bussiness.deviceJpg.mapper.TbDeviceJpgMapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import java.io.File;

import javax.imageio.stream.FileImageOutputStream;

import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mars
 * @since 2017-08-24
 */
@Service
public class TbDeviceJpgServiceImpl extends ServiceImpl<TbDeviceJpgMapper, TbDeviceJpg> implements ITbDeviceJpgService {
	
	
	
	  @Override
	  public void byte2image(byte[] data,String path){
		    if(data.length<3||path.equals("")){}//判断输入的byte是否为空
		    try{
		    FileImageOutputStream imageOutput = new FileImageOutputStream(new File(path));//打开输入流
		    imageOutput.write(data, 0, data.length);//将byte写入硬盘
		    imageOutput.close();
		    System.out.println("Make Picture success,Please find image in " + path);
		    } catch(Exception ex) {
		      System.out.println("Exception: " + ex);
		      ex.printStackTrace();
		    }
		  }
	
}
